package com.smart.campus.web.controller.student;

import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.page.TableDataInfo;
import com.smart.campus.framework.util.ShiroUtils;
import com.smart.campus.framework.web.service.DictService;
import com.smart.campus.school.domain.ExamAnswer;
import com.smart.campus.school.domain.ExamPaper;
import com.smart.campus.school.domain.StudentPaper;
import com.smart.campus.school.service.IStudentPaperService;
import com.smart.campus.web.utils.StudentUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 学生练习试卷Controller
 * 
 * @author Zhihe.Li
 * @date 2020-06-17
 */
@Controller
@RequestMapping("/student/paper")
public class StudentPaperController extends BaseController
{
    private String prefix = "student/paper";

    @Autowired
    private IStudentPaperService studentPaperService;
    @Autowired
    private DictService dictService;
    @GetMapping()
    public String paper()
    {
        return prefix + "/paper";
    }

    /**
     * 查询学生练习试卷列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StudentPaper studentPaper)
    {
        startPage();
        studentPaper.setStudentId(StudentUtil.getStudentId());
        List<StudentPaper> list = studentPaperService.selectStudentPaperList(studentPaper);
        return getDataTable(list);
    }

    /**
     * 打印
     */
    @GetMapping("/print/{id}")
    public String print(@PathVariable("id") Long id, ModelMap mmap) {

        StudentPaper examPaper = studentPaperService.selectStudentPaperById(id);
        examPaper.setSubjectName(dictService.getLabel("sc_subject_type",String.valueOf(examPaper.getSubject())));
        mmap.put("examPaper", examPaper);
        mmap.put("user", ShiroUtils.getSysUser());
        return prefix + "/print";
    }

    /**
     * 试卷答案打印
     */
    @GetMapping("/answer/print/{id}")
    public String answerPrint(@PathVariable("id") Long id, ModelMap mmap) {
        Map<Integer, Map<Long, List<ExamAnswer>>> result = studentPaperService.getPaperAnswerByPaperId(id);
        mmap.put("answer", result);
        mmap.put("user", ShiroUtils.getSysUser());
        return prefix + "/answerPrint";
    }

}
